package me.zhengjie.pm.projectstageprogress.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.pm.projectbase.domain.ProjectBase;
import me.zhengjie.pm.projectstage.domain.ProjectStage;
import org.hibernate.annotations.ColumnTransformer;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;

/**
* @author yuxj
* @date 2020-04-14
*/
@Entity
@Data
@Table(name="project_stage_progress")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class ProjectStageProgress implements Serializable {

    /** ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    /** 项目ID */
    @Column(name = "project_id",nullable = false)
    @NotNull
    private Integer projectId;

    @OneToOne
    @JoinColumn(name = "project_id", insertable = false, updatable = false)
    private ProjectBase projectBase;

    /** 项目阶段ID */
    @Column(name = "stage_id",nullable = false)
    @NotNull
    private Integer stageId;

    /** 任务累计完成进度 */
    @Column(name = "progress")
    private Double progress;

    /** 填报时间 */
    @Column(name = "update_time")
    private Timestamp updateTime;

    /** 开始时间 */
    @Column(name = "start_time",nullable = false)
    @NotNull
    private Timestamp startTime;

    /** 结束时间 */
    @Column(name = "end_time",nullable = false)
    @NotNull
    private Timestamp endTime;

    /** 此周期项目所耗时（人/天） */
    @Column(name = "time_use",nullable = false)
    private Double timeUse;

    /** 具体描述 */
    @Column(name = "`describe`")
//    @ColumnTransformer(
//            read = "CAST(AES_DECRYPT(UNHEX(`describe`), 'rjb') as char(128))",
//            write = "HEX(AES_ENCRYPT(?, 'rjb'))"
//    )
    private String describe;

    public void copy(ProjectStageProgress source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}